package leecode.stringAndArray.String;

public class ReverseWords {
    public static void main(String[] args) {
        ReverseWords reverseWords = new ReverseWords();
        String solution = reverseWords.solution("a good   example");
        System.out.println(solution);
    }

    public String solution(String s){
        String[] str = s.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        int len = str.length;
        while(len-- >0){
            if(!str[len].equals("")){
                if (stringBuilder.length()!=0){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(str[len]);
            }

        }
        return stringBuilder.toString().trim();
    }
}
